|
1
|
|
|
module.localFunctions = { |
|
2
|
|
|
manageDateField: function (inCurrentList, crtIndex) { |
|
3
|
|
|
var crtResult = ''; |
|
4
|
|
|
if (inCurrentList[crtIndex] === null) { |
|
5
|
|
|
crtResult = 'null'; |
|
6
|
|
|
} else { |
|
7
|
|
|
crtResult = inCurrentList[crtIndex].replace('T', ' ').replace('Z', ''); |
|
8
|
|
|
} |
|
9
|
|
|
return crtResult; |
|
10
|
|
|
} |
|
11
|
|
|
}; |
|
12
|
|
|
module.exports = { |
|
13
|
|
|
buildAuthenticationHeader: function (inAuthenticationArray) { |
|
14
|
|
|
var aReturn; |
|
15
|
|
|
switch (inAuthenticationArray.type) { |
|
16
|
|
|
case 'Addin': |
|
17
|
|
|
aReturn = inAuthenticationArray.credentials_Addin; |
|
18
|
|
|
break; |
|
19
|
|
|
case 'SAML': |
|
20
|
|
|
aReturn = inAuthenticationArray.credentials_SAML; |
|
21
|
|
|
break; |
|
22
|
|
|
default: |
|
23
|
|
|
aReturn = false; |
|
24
|
|
|
break; |
|
25
|
|
|
} |
|
26
|
|
|
return aReturn; |
|
27
|
|
|
}, |
|
28
|
|
|
buildCurrentListAttributeValues: function (inObjectListsConfiguredAttributes, inCurrentList) { |
|
29
|
|
|
var crtListAttributes = []; |
|
30
|
|
|
Object.keys(inObjectListsConfiguredAttributes).map(function (itemList) { |
|
31
|
|
|
if (itemList.substring(0, 4) === 'Date') { |
|
32
|
|
|
crtListAttributes[itemList] = module.localFunctions.manageDateField(inCurrentList, inObjectListsConfiguredAttributes[itemList]); |
|
33
|
|
|
} else { |
|
34
|
|
|
crtListAttributes[itemList] = inCurrentList[inObjectListsConfiguredAttributes[itemList]]; |
|
35
|
|
|
} |
|
36
|
|
|
}); |
|
37
|
|
|
return crtListAttributes; |
|
38
|
|
|
}, |
|
39
|
|
|
buildCurrentItemValues: function (fieldAttributes, item) { |
|
40
|
|
|
var crtRecord = []; |
|
41
|
|
|
var counterF = 0; |
|
42
|
|
|
Object.keys(fieldAttributes).map(function (itemF) { |
|
43
|
|
|
switch (fieldAttributes[itemF]['Type']) { |
|
44
|
|
|
case 'DateTime': |
|
45
|
|
|
crtRecord[counterF] = module.localFunctions.manageDateField(item, fieldAttributes[itemF]['Technical Name']); |
|
46
|
|
|
break; |
|
47
|
|
|
case 'Lookup': |
|
48
|
|
|
case 'User': |
|
49
|
|
|
crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name'] + 'Id']; |
|
50
|
|
|
break; |
|
51
|
|
|
default: |
|
52
|
|
|
crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']]; |
|
53
|
|
|
break; |
|
54
|
|
|
} |
|
55
|
|
|
counterF++; |
|
56
|
|
|
}); |
|
57
|
|
|
return crtRecord; |
|
58
|
|
|
}, |
|
59
|
|
|
buildCurrentRecordValues: function (inFieldsArray, crtRecordValues) { |
|
60
|
|
|
var crtRecordGM = []; |
|
61
|
|
|
var counterGM = 0; |
|
62
|
|
|
Object.keys(inFieldsArray).map(function (itemGM) { |
|
63
|
|
|
if (inFieldsArray[itemGM] === 'HtmlSchemaXml') { |
|
64
|
|
|
crtRecordGM[counterGM] = JSON.stringify(crtRecordValues[inFieldsArray[itemGM]]); |
|
65
|
|
|
} else { |
|
66
|
|
|
crtRecordGM[counterGM] = crtRecordValues[inFieldsArray[itemGM]]; |
|
67
|
|
|
} |
|
68
|
|
|
counterGM++; |
|
69
|
|
|
}); |
|
70
|
|
|
return crtRecordGM; |
|
71
|
|
|
}, |
|
72
|
|
|
buildRequestQuery: function (targetSharePointURL, arStandardLists, crtListName, queryType, inData) { |
|
73
|
|
|
var queryPrefix = ''; |
|
74
|
|
|
if (Object.keys(arStandardLists).indexOf(queryType) > -1) { |
|
75
|
|
|
queryPrefix = '_api/Web/' + arStandardLists[queryType]['APItrunk'] |
|
76
|
|
|
+ '/' + arStandardLists[queryType]['APIfunction'] + '(\'' |
|
77
|
|
|
+ crtListName + '\')/' + arStandardLists[queryType]['APIelement']; |
|
78
|
|
|
} else { |
|
79
|
|
|
queryPrefix = '_api/Web/' + queryType; |
|
80
|
|
|
} |
|
81
|
|
|
var headerOptions = inData.headers; |
|
82
|
|
|
headerOptions['Accept'] = 'application/json;odata=verbose'; |
|
83
|
|
|
return { |
|
84
|
|
|
url: targetSharePointURL + queryPrefix, |
|
85
|
|
|
headers: headerOptions, |
|
86
|
|
|
json: true |
|
87
|
|
|
}; |
|
88
|
|
|
}, |
|
89
|
|
|
decideBlackListWhiteList: function (inDecisionValue, inEvaluatedValueForBlackList, inBlackListArray, inEvaluatedValueForWhiteList, inWhiteListArray, inValueToEvaluate) { |
|
90
|
|
|
var bolReturn = false; |
|
91
|
|
|
if ((inDecisionValue === inEvaluatedValueForBlackList) && (inBlackListArray.indexOf(inValueToEvaluate) === -1)) { |
|
92
|
|
|
bolReturn = true; |
|
93
|
|
|
} |
|
94
|
|
|
if ((inDecisionValue === inEvaluatedValueForWhiteList) && (inWhiteListArray.indexOf(inValueToEvaluate) > -1)) { |
|
95
|
|
|
bolReturn = true; |
|
96
|
|
|
} |
|
97
|
|
|
return bolReturn; |
|
98
|
|
|
}, |
|
99
|
|
|
internalQueryStructureArray: function (maxRecords) { |
|
100
|
|
|
return { |
|
101
|
|
|
'Fields': {'APItrunk': 'Lists', 'APIfunction': 'GetByTitle', 'APIelement': 'Fields'}, |
|
102
|
|
|
'GroupMembers': {'APItrunk': 'SiteGroups', 'APIfunction': 'GetById', 'APIelement': 'Users'}, |
|
103
|
|
|
'Items': {'APItrunk': 'Lists', 'APIfunction': 'GetByTitle', 'APIelement': 'Items' + '?$top=' + maxRecords}, |
|
104
|
|
|
'Views': {'APItrunk': 'Lists', 'APIfunction': 'GetByTitle', 'APIelement': 'Views'} |
|
105
|
|
|
}; |
|
106
|
|
|
} |
|
107
|
|
|
}; |
|
108
|
|
|
|